package com.haozi.watchtomato.controller;

import com.github.pagehelper.PageInfo;
import com.haozi.watchtomato.dto.TomatoDto;
import com.haozi.watchtomato.dto.HaoziResponse;
import com.haozi.watchtomato.model.TomatoModel;
import com.haozi.watchtomato.service.ITomatoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Api(tags = "通用controller")
@RequestMapping(value = "/tomato")
@Slf4j
public class TomatoController {

    @Autowired
    private ITomatoService tomatoService;

    @ApiOperation("查询数据列表")
    @PostMapping("/queryTomatoList")
    public HaoziResponse queryTomatoList(@RequestBody TomatoModel model) {
        PageInfo<TomatoDto> tomatoDtos = tomatoService.queryTomatoList(model);
        return new HaoziResponse().success(tomatoDtos);
    }

    @ApiOperation("保存数据")
    @PostMapping("/saveTomato")
    public HaoziResponse saveTomato(@RequestBody TomatoModel model) {
        int result = tomatoService.save(model);
        return new HaoziResponse().success(result);
    }

    @ApiOperation("修改数据")
    @PostMapping("/updateTomato")
    public HaoziResponse updateTomato(@RequestBody TomatoModel model) {
        int result = tomatoService.update(model);
        return new HaoziResponse().success(result);
    }

    @ApiOperation("删除数据")
    @PostMapping("/deleteTomato")
    public HaoziResponse deleteTomato(@RequestBody TomatoModel model) {
        int result = tomatoService.delete(model.getId());
        return new HaoziResponse().success(result);
    }


}
